package mcsm.OperationCenter;

import java.util.ArrayList;

import mcsm.DataBaseIntegration.DataBaseConnect;
import mcsm.DataBaseIntegration.DeleteVIPConnect;
import mcsm.DataBaseIntegration.SearchConnect;
import mcsm.DataBaseInterface.Connector;
import mcsm.Model.VIP;

public class VIPManagement {
	private ArrayList<VIP> VIPList;
	private DataBaseConnect database;
	private Connector connector;

	public VIPManagement() {
		database = DataBaseConnect.getDatabase();
		VIPList = new ArrayList<VIP>();
	}


	public ArrayList<VIP> searchVIP(String VIPID) {
		
		if (VIPID.isEmpty()) {
			VIPList=SearchConnect.searchForVIP(null, "VIP");
		} else {
			VIPList=SearchConnect.searchForVIP(VIPID, "VIP");
		}
		
		return VIPList;
	}

	public ArrayList<VIP> deleteVIP(int index) {		
		if (index < 0 || VIPList.size() - 1 < index)
			return null;
		
		VIP tempVIP = VIPList.get(index);
		connector = new DeleteVIPConnect(tempVIP);
		database.connect(connector);
		VIPList.remove(index);
		return VIPList;
	}


	public ArrayList<VIP> getVIPList() {
		return VIPList;
	}

	public VIP getVIP(int index) {

		if (index < 0)
			return null;

		if (VIPList.size() - 1 < index)
			return null;

		return VIPList.get(index);
	}

	public void clearVIPList() {
		VIPList = new ArrayList<VIP>();
	}
}
